﻿using Development.Network.Tcp;
using Development.Tools;

namespace Development.Network.Rpc
{
    /// <summary>
    /// rpc 服务器
    /// </summary>
    public class RpcServer : Rpc
    {
        protected TcpServer _server;
        public RpcServer(int numConnections, int recvBufferSize)
        {
            _server = new TcpServer(numConnections, recvBufferSize);
            _server.EventRecvMsg += RpcRecv;
        }

        public bool Listen(int port, string ip = "")
        {
            return _server.Listen(port, ip);
        }
        protected override void RpcSend(ISender sender,RpcRequst requst)
        {
            if (sender != null)
            {
                sender.Send(requst.Pack());
            }
            else
            {
                Log.WriteLog(ELogLevel.LOG_ERROR, "rpc sender is null");   
            }
        }
       
    }
}
